package com.example.demo1.expr;

import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author Lenovo
 需求
筛选出卡路里小于400的菜肴

对筛选出的菜肴进行一个排序

获取排序后菜肴的名字
* */
public class DishSelect {
     List<Dish> dishes = Arrays.asList(
             new Dish("A",false,300),
             new Dish("b",false,130),
             new Dish("c",true,1400),
             new Dish("d",false,710),
             new Dish("e",true,610),
             new Dish("f",true,310)
     );
     @Test
     public void test(){
      dishes.stream().filter(d -> d.getCalories() < 400)
              .sorted(Comparator.comparing(Dish::getCalories))
              .map(Dish::getName)
              .collect(Collectors.toList())
              .forEach(System.out::println);
     }
}
